
TOOL_NAME=bspmem


CROSS_COMPILE ?= aarch64-none-linux-gnu

CROSS=$(CROSS_COMPILE)
CC  = $(CROSS)-gcc
STRIP=$(CROSS)-strip
INCDIR=inc
SRCDIR=src
OUTDIR=build
OUTFILE=$(OUTDIR)/$(TOOL_NAME)

#添加头文件目录
CFG_INC +=-I$(INCDIR) -Iconfig


#添加源文件
TOOLS_SRC=$(wildcard $(SRCDIR)/*.c)
TOOLS_OBJ=$(patsubst %.c,$(SRCDIR)/%.o, $(notdir $(TOOLS_SRC)))
ALL_OBJ=$(TOOLS_OBJ)

#添加编译宏
CFG_DEFS += -DTARGET_ARM

#编译选项
CFG_CFLAGS=-Wall -Wunused
CFG_CFLAGS +=-mlittle-endian
CFG_CFLAGS += $(USER_CFLAGS)
COMPIER_FLAGS= -c  -W

#链接选项
OSDRV_CROSS_CFLAGS := -fstack-protector-strong -fPIE
OSDRV_CROSS_LDFLAGS ?= -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -fPIE -pie
USER_CFLAGS:=$(OSDRV_CROSS_CFLAGS)
CFG_LIB_ARM=$(OSDRV_CROSS_LDFLAGS)
CFG_LIB  +=$(USER_CFLAGS)
CFG_LIB  +=$(CFG_LIB_ARM)

#调试选项
CFG_DEBUG = -g3

CFG_FLAGS = $(CFG_CFLAGS) $(CFG_DEBUG) $(CFG_INC) $(CFG_DEFS)
LINK_FLAGS = $(CFG_DEFS) $(CFG_DEBUG)

COMPILE=@$(CC) $(CFG_FLAGS) $(COMPIER_FLAGS) -o "$@" "$<"
LINK=$(CC) -o "$(OUTDIR)/$@" $(ALL_OBJ) $(CFG_LIB)

%.o : %.c
	$(COMPILE)


all: clean $(TOOL_NAME)

$(TOOL_NAME):$(ALL_OBJ)
	$(LINK)
	$(STRIP) $(OUTFILE)
	cd $(OUTDIR);\
	ln -s $(TOOL_NAME) bspmd;\
	ln -s $(TOOL_NAME) bspmm;\
	ln -s $(TOOL_NAME) dumpregs;\
	cd -

# Clean this project
clean:
	rm -f $(ALL_OBJ)
	rm -rf $(OUTDIR)/*

# Clean this project and all dependencies
distclean: clean

